<?php

namespace App\Http\Controllers;

use App\Http\Service\Douban\DoubanpostService;
use App\Http\Service\Weibo\WeibopostService;
use App\Http\Service\ViewcountService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
class JiankongController extends BaseController
{
    private $getRules=[
            'unique_id'=> 'required',
        ];
    private  $getRulesMessage=[
            'unique_id.required'=> '唯一标识【unique_id】不能为空',
        ];

    public $repository;
    public function __construct(DoubanpostService $repository,ViewcountService $historyservice,WeibopostService $weibopostservice)
    {
        parent::__construct();
        $this->repository = $repository;
        $this->historyservice = $historyservice;
        $this->weibopostservice=$weibopostservice;
    }

    /**
     *  监控-列表
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function getList(Request $request)
    {
        $data=[
            'title'=>$request->input("title"),
            'group_type'=>$request->input("group_type"),
            'unit_type'=>$request->input("unit_type"),
        ];
        $this->success($this->repository->getList($request,$data));
    }

    /**
     *  监控-详情
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function dataDetail(Request $request)
    {
        $data=[
            'unique_id'=>$request->input("unique_id"),
            'people_id'=>$request->input("people_id"),
        ];
        $this->checkrule($data,$this->getRules,$this->getRulesMessage);
        //添加历史记录
        $hdata=$data;
        $hdata['type']='1';
        $first=DB::table("douban_post")->where(['unique_id'=>$data['unique_id']])->first();
        if(empty($first)){
            $this->error("【unique_id】不存在");
        }
        $hdata['type_son']=$first->group_type;
        $hdata['title']=$first->title;
        //dd($hdata);
        $this->historyservice->addDate($request,$hdata);

        $this->success($this->repository->dataDetail($request,$data));
    }

    //微博列表
    public function getwbList(Request $request)
    {
        $data=[
            'is_weibo_chaohua'=>$request->input("is_weibo_chaohua"),
            'search_content'=>$request->input("search_content"),
            'user_id'=>$request->input("user_id"),
        ];
        $this->success($this->weibopostservice->getList($request,$data));
    }

    //微博昵称标签
    public function getwbLableList(Request $request)
    {
        $data=[
            'is_weibo_chaohua'=>$request->input("is_weibo_chaohua"),
        ];
        $this->success($this->weibopostservice->getwbLableList($request,$data));
    }



    

  

}
